<template>
  <div class="matching">
    <TopInfo />
    <TopTabs2 />
    <div class="content">
      <div class="form-title">{{ title }}</div>
      <div class="content-form">
        <el-form :model="form">
          <el-row>
            <el-col :span="24">
              <el-form-item label="企业名称" :label-width="formLabelWidth">
                <el-input
                  v-model="form.entname"
                  autocomplete="off"
                  placeholder="请输入企业名称"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="联系人" :label-width="formLabelWidth">
                <el-input
                  v-model="form.contacts"
                  autocomplete="off"
                  placeholder="请输入联系人"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="联系电话" :label-width="formLabelWidth">
                <el-input
                  v-model="form.tel"
                  autocomplete="off"
                  placeholder="请输入联系电话"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="单位地址" :label-width="formLabelWidth">
                <el-input
                  v-model="form.address"
                  autocomplete="off"
                  placeholder="请输入单位地址"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注" :label-width="formLabelWidth">
                <el-input
                  type="textarea"
                  :rows="6"
                  v-model="form.remark"
                  autocomplete="off"
                  placeholder="请输入备注"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="SetValue()" class="sub"
            >确 定</el-button
          >
        </div>
      </div>
    </div>
    <BottomInfo />
  </div>
</template>

<script>
import BottomInfo from "../components/BottomInfo";
import TopInfo from "../components/TopInfo";
import TopTabs2 from "../components/TopTabs2";
export default {
  name: "AddForm",
  data() {
    return {
      form: {
        typeid: "",
        tel: "",
        entname: "",
        contacts: "",
        remark: "",
        address:""
      },
      title: "",
      formLabelWidth: "120px",
    };
  },
  components: {
    BottomInfo,
    TopInfo,
    TopTabs2,
  },
  created() {},
  mounted() {
    this.form.typeid = this.$cookies.get("newid");
    this.title = this.$cookies.get("title");
  },
  methods: {
    SetValue() {
      if (!this.form.entname) {
        this.$message({
          message: "企业名称不能为空",
          type: "warning",
        });
        return false;
      }
      if (!this.form.contacts) {
        this.$message({
          message: "联系人不能为空",
          type: "warning",
        });
        return false;
      }
      if (!this.form.tel) {
        this.$message({
          message: "联系电话不能为空",
          type: "warning",
        });
        return false;
      }
      if (!this.form.remark) {
        this.$message({
          message: "备注不能为空",
          type: "warning",
        });
        return false;
      }
      this.$axios({
        url: "/New/AddOrderInfo",
        method: "post",
        data: {
          userdata: this.$cookies.get("userdata") || "",
          typeid: this.form.typeid,
          tel: this.form.tel,
          entname: this.form.entname,
          contacts: this.form.contacts,
          address: this.form.address,
          remark: this.form.remark,
        },
        transformRequest: [
          function (data) {
            let ret = "";
            for (let it in data) {
              ret +=
                encodeURIComponent(it) +
                "=" +
                encodeURIComponent(data[it]) +
                "&";
            }
            return ret;
          },
        ],
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
      })
        .then((res) => {
          // console.log(res);
          //   if (res.data.status == -10003) {
          //   }
          if (res.data.status == 1) {
            this.$message({
              message: "提交成功",
              type: "success",
            });
            setTimeout(() => {
              this.$router.push({ name: "Home" });
            }, 1000);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style scoped>
.matching {
  min-height: 800px;
  /* overflow-y: auto; */
}
.content {
  background-color: #f4f6fc;
  padding: 25px 0;
}
.content-form {
  width: 600px;
  margin: 50px auto;
  margin-bottom: 100px;
  /* min-height: 400px; */
}
.dialog-footer {
  text-align: center;
}
.sub {
  width: 360px;
  margin-top: 50px;
}
.form-title {
  font-size: 20px;
  text-align: center;
  color: #000;
}
</style>
